<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Layui</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="/addons/hc_answer/template/plugins/layui/css/layui.css" media="all" />
	</head>

	<body>
		<div style="margin: 15px;">
			<fieldset class="layui-elem-field">
				<legend>添加题目</legend>
			
				<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
					<div class="layui-tab-content" >
						<!-- 基础设置 开始-->
						<form class="layui-form" action="" id="form">
							<div class="layui-form-item">
							    <label class="layui-form-label">题目标题</label>
							    <div class="layui-input-block">
							      <input type="text" name="question" value="{$info['question']}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger">
							    </div>
							</div>
							<div class="layui-form-item">
							      <label class="layui-form-label">题目分组</label>
							      <div class="layui-input-inline">
							        <select name="type_id">
							          <option value="">请选择分组</option>
							          {loop $cate $item}
							          <optgroup label="{$item['name']}">
							          	{loop $item['children'] $v}
							            <option value="{$v['id']}" {if $v['id']==$info['type_id']}selected="selected"{/if}>{$v['name']}</option>
							          	{/loop}
							          </optgroup>
							          {/loop}
							        </select>
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">答案A</label>
							    <div class="layui-input-block">
							      <input type="text" name="answer_a" value="{$info['answer_a']}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger">
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">答案B</label>
							    <div class="layui-input-block">
							      <input type="text" name="answer_b" value="{$info['answer_b']}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger">
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">答案C</label>
							    <div class="layui-input-block">
							      <input type="text" name="answer_c" value="{$info['answer_c']}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger">
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">答案D</label>
							    <div class="layui-input-block">
							      <input type="text" name="answer_d" value="{$info['answer_d']}" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input layui-form-danger">
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">正确答案</label>
							    <div class="layui-input-block">
							      <input type="radio" name="answer" value="A" title="A" {if $info['answer']=='A'}checked="checked"{/if}{if empty($info['answer'])}checked="checked"{/if}>
							      <input type="radio" name="answer" value="B" title="B" {if $info['answer']=='B'}checked="checked"{/if}>
							      <input type="radio" name="answer" value="C" title="C" {if $info['answer']=='C'}checked="checked"{/if}>
							      <input type="radio" name="answer" value="D" title="D" {if $info['answer']=='D'}checked="checked"{/if}>
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">难易程度</label>
							    <div class="layui-input-block">
							      <input type="radio" name="easy" value="1" title="简单" {if $info['easy']=='1'}checked="checked"{/if}{if empty($info['easy'])}checked="checked"{/if}>
							      <input type="radio" name="easy" value="2" title="一般" {if $info['easy']=='2'}checked="checked"{/if}>
							      <input type="radio" name="easy" value="3" title="复杂" {if $info['easy']=='3'}checked="checked"{/if}>
							    </div>
							</div>
							<input type="hidden" name="id" value="{$info['id']}" >
							<div class="layui-form-item">
							    <div class="layui-input-block">
							      <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="demo1">立即提交</button>
							      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
							    </div>
							</div>

							</form>
						<!-- 题目设置 结束-->
					</div>
				</div>	
			</fieldset>
		</div>

		<script type="text/javascript" src="/addons/hc_answer/template/plugins/layui/layui.js"></script>
		<script>
			layui.use(['form','laypage','layer'], function() {
				var $ = layui.jquery,
				form = layui.form();
				form.render();
				form.on('submit(demo1)', function(data) {
					$.ajax({
			            url:"{php echo $this->createWebUrl('librarydo');php}",
			            data:$('#form').serialize(),
			            type:"post",
			            dataType:"json",
			            success:function(data){
			            	if(data.code=='1'){
			                	layer.alert(data.msg, {icon: 6},function(index){
			                		var index = parent.layer.getFrameIndex(window.name);
			                		parent.layer.close(index)
			                	});
								
			            	}else{
			                	layer.alert(data.msg, {icon: 5});
			            	}
			            },
			            error:function(data){
			                layer.alert('请稍后重试', {icon: 5});
			            }
			        });
					return false;
				});
				
			});
		</script>

	</body>

</html>